package com.example.learn_gl_android.anglib.core.transform

import android.opengl.Matrix
import com.example.learn_gl_android.anglib.util.math.Matrix4x4

class DefaultTransform : AbstractTransform() {


    override fun rotate(ax:Float, ay:Float, az:Float) {
        Matrix.rotateM(transformMatrix.elements, 0,
            ax, 1f,0f,0f)
        Matrix.rotateM(transformMatrix.elements, 0,
            ay, 0f,1f,0f)
        Matrix.rotateM(transformMatrix.elements, 0,
            az, 0f,0f,1f)

    }

    override fun translate(x:Float, y: Float, z:Float) {
        Matrix.translateM(transformMatrix.elements, 0, x,y,z)
    }

    override fun scale(x:Float, y: Float, z:Float) {
        Matrix.scaleM(transformMatrix.elements, 0, x,y,z)
    }

    override fun transform(modelMatrix: FloatArray): FloatArray {
        val ret = Matrix4x4.one()
        Matrix.multiplyMM(ret.elements, 0,
                            transformMatrix.elements, 0,
                            modelMatrix, 0)
        return ret.elements
    }
}